
export default {
    install(Vue) {
    // el-form rules
    Vue.prototype.$validator = function (rules) {
      if (rules?.constructor !== Object) {
        console.error('$validator 验证参数错误!!!')
        return {}
      }
      for (let key in rules) {
        rules[key] = this.$validatorArray(rules[key])
      }
      return rules
    }

    // el-form-item rules
    Vue.prototype.$validatorArray = function (rules) {
        if (Array.isArray(rules)) {
          let defaultRule = {
            required: true,
            trigger: ['blur', 'change']
          }
          let r = []
          for (let v of rules) {
            if (v.constructor !== Object) continue
            r.push(rulesHandler({ ...defaultRule, ...v }))
          }
          return r
        } else {
          console.error('$validatorArray 验证参数错误!!!')
          return []
        }
      }
  }
  }